package com.woniuxy.driverschool.controller;


import com.woniuxy.driverschool.entity.*;
import com.woniuxy.driverschool.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author: xyq
 * @version: 1.0.0
 * @create: 2021/10/11 17:49
 * @description: TODO
 */
@RestController
@RequestMapping()
public class ReportController {

    @Autowired
    ReportService reportService;
    private static final String CONTROLLER_MAPPING = "report";

    //查询学员报审报告
    @GetMapping(CONTROLLER_MAPPING +"/list/page")
    public ResponseResult<PageBean<Report>> getReport(Report report ,Student student,int pageIndex, int pageSize,String startTime, String endTime)
            throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
        Date startTime1 = null;
        Date endTime1 = null;
        if(!(null == startTime || "".equals(startTime))) {
            startTime1 = sdf.parse(startTime);
        }
        if(!(null == endTime || "".equals(endTime))) {
            endTime1 = sdf.parse(endTime);
        }
        report.setStudent(student);
        System.out.println(report);
        System.out.println("pageSize：" + pageSize);
        System.out.println("pageIndex：" + pageIndex);
        int selectCountReportsByPage = reportService.selectCountReportsByPage(report, startTime1, endTime1);
        List<Report> reports = reportService.selectAllReportsByPage(report, pageIndex, pageSize, startTime1, endTime1);
        PageBean<Report> pageBean = new PageBean<Report>();
        pageBean.setBeanList(reports);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(selectCountReportsByPage);
        return new ResponseResult<PageBean<Report>>(pageBean, 200, "ok");
    }

//    //修改审核状态
//    @PutMapping("/report")
//    public ResponseResult modifyReport(@RequestBody Report report){
//        reportService.updateReport(report.getReportStauts(), null, report.getReportSubject(), null, null, report.getRid());
//        System.out.println("修改学生："+report);
//        return new ResponseResult(null,200,"ok");
//    }
}